package com.seio.edc.common;

import javax.servlet.http.HttpServletRequest;

import org.springframework.ui.ModelMap;
import org.springframework.web.util.HtmlUtils;

public class HtmlModelMap extends ModelMap {

    /**
     * serialVersionUID
     */
    private static final long serialVersionUID = -2342355630054661514L;

    public Object put(String key, Object value) {

        try {
            if (value == null) {
                return super.put(key, null);
            }

            if (value instanceof String) {
                return super.put(key, HtmlUtils.htmlEscape((String) value));
            }

            return super.put(key, value);

        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }

    public Object putNoEscape(String key, Object value) {
        return super.put(key, value);
    }

    public static String getRequestParam(HttpServletRequest request, String paramName) {
        try {
            
        	return request.getParameter(paramName);
            
            // return new
            // String(request.getParameter(paramName).getBytes("iso8859-1"),
            // "utf-8");
            // } catch (UnsupportedEncodingException e) {
            // e.printStackTrace();
            // return "";
        } catch (Exception e) {
            return "";
        }
    }

}
